import React, { useState, useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import Field from '@ant-design/pro-field';

import { Tooltip } from 'antd';
import { useIntl } from 'umi';
import { page, getrequestloginfo } from './service';

const ErrorLog = () => {
  const actionRef = useRef();

  //请求详情
  const requestloginfo = async (fields) => {
    await getrequestloginfo(fields).then((re) => {
      setCurrentRow(re.data || {});
    });
  };


  const valueEnum = new Map();
  valueEnum.set(true, { text: '计划外', status: 'Error', });
  valueEnum.set(false, { text: '计划内', status: 'Success', });
  const columns = [
    {
      title: '主键',
      dataIndex: 'id',
      tip: '规则名称是唯一的key',
      hideInSearch: true,
      hideInTable: true,
    },

    {
      title: '错误代码',
      align: 'center',
      width: 80,
      dataIndex: 'errorCode',
      valueType: 'textarea',
    },
    {
      title: '意外异常',
      width: 100,
      dataIndex: 'isUnexpected',
      valueEnum,
    },
    {
      title: '错误信息',
      width: 200,
      dataIndex: 'errorMessage',
      valueType: 'textarea',
      hideInSearch: true,
      ellipsis: {
        showTitle: false,
      },
      render: address => (
        <Tooltip placement="topLeft" >
          {address}
        </Tooltip>
      ),
    },

    {
      title: '堆栈',
      dataIndex: 'stackTrace',
      valueType: 'textarea',
      hideInSearch: true,
    },
    {
      title: '错误时间',
      width: 90,
      align: 'center',
      dataIndex: 'createAt',
      valueType: 'dateTime',
      hideInSearch: true,
    }
  ];
  const intl = useIntl();
  return (
    <PageContainer>
      <ProTable
        headerTitle="请求日志"
        actionRef={actionRef}
        rowKey="id"
        search={{
          labelWidth: 120,
        }}
        request={async (params) => {
          var queryData = [];
          var total = 0;
          await page(JSON.stringify(params)).then((re) => {
            queryData = re.data.data;
            total = re.data.total;
          });
          return {
            data: queryData,
            success: true,
            total: total,
          };
        }}
        columns={columns}
        pagination={{ defaultPageSize: 10 }}
      />
    </PageContainer>
  );
};

export default ErrorLog;
